package com.lxp.project.system.service.impl;

import com.lxp.common.utils.StringUtils;
import com.lxp.project.system.domain.SysOperLog;
import com.lxp.project.system.mapper.SysOperLogMapper;
import com.lxp.project.system.service.ISysOperLogService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志 服务层处理
 *
 * @author lxp
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService {
    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    @Override
    public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
        QueryWrapper lqw = new QueryWrapper();
        if (StringUtils.isNotBlank(operLog.getOperIp())) {
            lqw.like(SysOperLog::getOperIp, operLog.getOperIp());
        }
        if (StringUtils.isNotBlank(operLog.getTitle())) {
            lqw.like(SysOperLog::getTitle, operLog.getTitle());
        }
        if (operLog.getBusinessType() != null) {
            lqw.eq(SysOperLog::getBusinessType, operLog.getBusinessType());
        }
        if (operLog.getStatus() != null) {
            lqw.eq(SysOperLog::getStatus, operLog.getStatus());
        }
        if (operLog.getBusinessTypes() != null && operLog.getBusinessTypes().length > 0) {
            lqw.in(SysOperLog::getBusinessType, operLog.getBusinessType());
        }
        if (StringUtils.isNotBlank(operLog.getOperName())) {
            lqw.like(SysOperLog::getOperName, operLog.getOperName());
        }
        if (operLog.getBeginTime() != null) {
            lqw.ge(SysOperLog::getOperTime, operLog.getBeginTime());
        }
        if (operLog.getEndTime() != null) {
            lqw.le(SysOperLog::getOperTime, operLog.getEndTime());
        }
        lqw.orderBy(SysOperLog::getOperId,false);
        return this.list(lqw);
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog() {
        mapper.cleanOperLog();
    }
}
